package com.jier.common.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 正则表达式
 * Created by jie_r on 2016/10/12.
 */
public class RegularUtil {
    /**
     * 手机号正则表达式
     */
    public static final String PHONE_REGEX = "0?(13|14|15|17|18)[0-9]{9}";

    /**
     * 密码正则表达式
     */
    public static final String PASSWORD_REGEX = "^[0-9a-zA-Z]{6,16}$";

    /**
     * 名字正则表达式
     */
    public static final String NAME_REGEX = "[A-Za-z0-9_\\-\\u4e00-\\u9fa5]+";

    /**
     * 邮箱正则表达式
     */
    public static final String EMAIL_REGEX = "^\\s*\\w+(?:\\.{0,1}[\\w-]+)*@[a-zA-Z0-9]+(?:[-.][a-zA-Z0-9]+)*\\.[a-zA-Z]+\\s*$";

    /**
     * IP正则表达式
     */
    public static final String IP = "(25[0-5]|2[0-4]\\d|[0-1]\\d{2}|[1-9]?\\d)\\.(25[0-5]|2[0-4]\\d|[0-1]\\d{2}|[1-9]?\\d)\\.(25[0-5]|2[0-4]\\d|[0-1]\\d{2}|[1-9]?\\d)\\.(25[0-5]|2[0-4]\\d|[0-1]\\d{2}|[1-9]?\\d)";

    public static boolean match(String regex, String name) {
        Pattern p = Pattern.compile(regex);
        Matcher m = p.matcher(name);
        return m.matches();
    }
}
